//
// Created by ziya on 2025/5/21.
//

#include <string.h>
#include "keywords.h"

typedef struct {
    const char *word;
    token_type token;
} keywords;

static keywords keyword_table[] = {
        {"if",     TOKEN_IF},
        {"else",   TOKEN_ELSE},
        {"while",  TOKEN_WHILE},
        {"for",    TOKEN_FOR},
        {"return", TOKEN_RETURN},
};

#define KEYWORD_COUNT (sizeof(keyword_table) / sizeof(keyword_table[0]))

token_type lookup_keyword(const char *lexeme) {
    for (int i = 0; i < KEYWORD_COUNT; ++i) {
        if (strcmp(lexeme, keyword_table[i].word) == 0) {
            return keyword_table[i].token;
        }
    }

    return TOKEN_IDENTIFIER;
}

